package com.libinyn.base.pms.serivce.impl.sys;


import com.libinyn.base.pms.entity.sys.SysUserRoleEntity;
import com.libinyn.base.pms.mapper.sys.SysUserRoleMapper;
import com.libinyn.base.pms.serivce.impl.BaseServiceImpl;
import com.libinyn.base.pms.serivce.sys.SysUserRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



/**
 * 用户与角色对应关系
 * @fileName: SysUserRoleServiceImpl.java
 * @author: bin.li01
 * @date: 2017/12/12 19:04 
 * @version: v1.0.0
 */
@Service
public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRoleEntity> implements SysUserRoleService {

	@Resource
	private SysUserRoleMapper sysUserRoleDao;

	@Override
	public void saveOrUpdate(Long userId, List<Long> roleIdList) {
		if(roleIdList.size() == 0){
			return ;
		}
		
		//先删除用户与角色关系
		sysUserRoleDao.deleteByPrimaryKey(userId);
		
		//保存用户与角色关系
		Map<String, Object> map = new HashMap<>();
		map.put("userId", userId);
		map.put("roleIdList", roleIdList);
		sysUserRoleDao.insertSelective(new SysUserRoleEntity());
	}

	@Override
	public List<Long> queryRoleIdList(Long userId) {
		return sysUserRoleDao.queryRoleIdList(userId);
	}

	@Override
	public void delete(Long userId) {
		sysUserRoleDao.deleteByPrimaryKey(userId);
	}
}
